package cn.iocoder.yudao.module.dine.config.api;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.api.dine.DineConfigApi;
import cn.iocoder.yudao.module.api.dine.vo.DineConfigVO;
import cn.iocoder.yudao.module.dine.config.convert.DineConfigConvert;
import cn.iocoder.yudao.module.dine.config.pojo.po.DineConfig;
import cn.iocoder.yudao.module.dine.config.service.core.CoreDineConfigService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;
import java.util.Map;
import java.util.Set;

import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/08/02
 */
@Service
@Validated
public class DineConfigApiImpl implements DineConfigApi {

    @Resource
    private CoreDineConfigService coreDineConfigService;

    @Override
    public DineConfigVO getDetail(Long shopId) {
        DineConfig config = coreDineConfigService.getOrCreate(shopId);
        return DineConfigConvert.INSTANCE.toViewObject(config);
    }

    @Override
    public Map<Long, DineConfigVO> getDetailMap(Set<Long> shopIds) {
        List<DineConfig> list = coreDineConfigService.getList(shopIds);
        if (CollUtil.isEmpty(list)) {
            return Map.of();
        }
        List<DineConfigVO> voList = DineConfigConvert.INSTANCE.toViewObject(list);
        return convertMap(voList, DineConfigVO::getShopId);
    }

}
